package com.ruoyi.jzzgl.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.jzzgl.domain.bo.JzzglSkjlBo;
import com.ruoyi.jzzgl.domain.vo.JzzglSkjlVo;
import com.ruoyi.jzzgl.service.JzzglSkjlService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.mybatis.core.page.PageQuery;

import jakarta.validation.Valid;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/jzzgl/record")
public class SkjlController extends BaseController {

    private final JzzglSkjlService skjlService;

    /**
     * 通过id获刷卡记录详情
     */
    @SaCheckPermission("jzzgl:skjl:query")
    @GetMapping("/{id}")
    public R<JzzglSkjlVo> getInfo(@PathVariable Long id) {
        return R.ok(skjlService.queryById(id));
    }

    /**
     * 分页查询刷卡记录列表
     */
    @SaCheckPermission("jzzgl:skjl:list")
    @GetMapping("/list")
    public TableDataInfo<JzzglSkjlVo> list(JzzglSkjlBo bo, PageQuery pageQuery) {
        return skjlService.queryPageList(bo, pageQuery);
    }

    /**
     * 批量上传刷卡记录
     */
    @SaIgnore
    @PostMapping("/batchUpload")
    public R<Void> batchUpload(@Valid @RequestBody List<JzzglSkjlBo> boList) {
        try {
            skjlService.batchInsert(boList);
        } catch (Exception e) {
            return R.fail("批量上传失败");
        }
        return R.ok();
    }
}
